using System;
using System.Xml;
using CommunityServer.Blogs.Components;
using CommunityServer.Components;

namespace CommunityServer.RollerBlogs.Components
{
	/// <summary>
	/// Summary description for RollerBlogRules.
	/// </summary>
	public class RollerBlogRules : ICSModule
	{
		public RollerBlogRules()
		{
		
		}

	    public void Init(CSApplication csa, XmlNode node)
	    {
	         csa.PreRenderPost +=new CSPostEventHandler(csa_PreRenderPost);
        }

        private void csa_PreRenderPost(IContent content, CSPostEventArgs e)
        {
            WeblogPost post = content as WeblogPost;
            if(post != null && post.BlogPostType == BlogPostType.Post)
            {
                if(post.IsExternal && post.DisplayExcerpt && !post.HasExcerpt)
                {
                    post.FormattedBody =  string.Format("{0} <a href=\"{1}\">{2}</a>", Formatter.RemoveHtml(post.FormattedBody,post.ExcerptSize), post.TitleUrl, ResourceManager.GetString("roller_ReadMore"));
                    post.Excerpt = post.FormattedBody;
                }
            }
        }
    }
}
